package com.alex.core.domain;



import com.ddcx.contants.enums.ApiResponseEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * 对应枚举类{@link com.ddcx.contants.enums.ApiResponseEnum}
 * @author xc
 * @param <T>
 */
@Data
public class ApiResponse<T> implements Serializable {

	public static final int SUCCESS_CODE = 0;
	private int code = 0;
	private String msg = "成功";
	private String errorMsg = null;
	private T data;
	public ApiResponse() {
		super();
	}

	public ApiResponse(T data) {
		super();
		this.data = data;
	}

	public ApiResponse(int code, String errorMsg,String msg) {
		this.code = code;
		this.errorMsg = errorMsg;
		this.msg  = msg;
	}

	public ApiResponse(Integer code, String msg) {
		super();
		this.code = code;
		this.msg = msg;
	}

	public ApiResponse( T data,String msg) {
		super();
		this.msg = msg;
		this.data = data;
	}

	public ApiResponse(int code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public ApiResponse(int code, T data) {
		this.code = code;
		this.data = data;
	}

	public ApiResponse(ApiResponseEnum apiResponseEnum) {
		this.code = apiResponseEnum.getCode();
		this.msg = apiResponseEnum.getErrorMsg();
        this.errorMsg = apiResponseEnum.getErrorMsg();
	}

	public void setCodeAndMsg(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 兼容.net
	 * @return
	 */
	public boolean getSuccess() {
		if(code==0){
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 兼容.net
	 * @return
	 */
	public String getErrorMsg() {return errorMsg;}

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}


}